/*
 * Created by SharpDevelop.
 * user: Robertux
 * Date: 11/03/2008
 * Time: 15:35
 * 
 * 
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using XmlClassLib;
using DataLayer;
using Inventador;

namespace WinApp
{
	/// <summary>
	/// Description of frmSesion.
	/// </summary>
	public partial class frmSesion : Form
	{
		private ConfigManager cm;
		private BaseDatos bdatos;		

		public frmSesion()
		{
			InitializeComponent();
		}
		
		public frmSesion(BaseDatos bdatosExterna): this()
		{
			this.bdatos = bdatosExterna;
			this.cm = new ConfigManager("app.config");
			this.lblError.Visible = false;
		}
		
		void BtnCancelarClick(object sender, EventArgs e)
		{
			this.Close();
		}
		
		void BtnAceptarClick(object sender, EventArgs e)
		{
			Usuario usr = new Usuario(0, this.txtUsuario.Text, this.txtClave.Text, "");
			if(usr.GetFromDbByNomClave(this.bdatos))
			{
				this.cm["usuario"] = usr.Id.ToString();
				this.Close();
			}
			else
			{
				this.lblError.Visible = true;
			}
		}
		
		void TxtUsuarioTextChanged(object sender, EventArgs e)
		{
			this.lblError.Visible = false;
		}
		
		void TxtClaveTextChanged(object sender, EventArgs e)
		{
			this.lblError.Visible = false;
		}
	}
}
